package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.entity.UserPracticeDetail;
import com.example.computer_exam_training_sys.service.UserPracticeDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/practiceDetail")
@CrossOrigin
public class UserPracticeDetailController {
    @Autowired
    private UserPracticeDetailService detailService;

    // 获取所有练习详情
    // 访问路径: http://localhost:8080/practiceDetail/list
    @GetMapping("/list")//通过
    public List<UserPracticeDetail> getAllPracticeDetails() {
        return detailService.getAllPracticeDetails();
    }

    // 根据练习ID获取详情
    // 访问路径: http://localhost:8080/practiceDetail/byPractice?practice_id=1
    @GetMapping("/byPractice")//通过
    public List<UserPracticeDetail> getDetailsByPracticeId(@RequestParam Integer practice_id) {
        return detailService.getDetailsByPracticeId(practice_id);
    }

    // 新增练习详情
    // 访问路径: http://localhost:8080/practiceDetail/add
    @PostMapping("/add")
    public String addPracticeDetail(@RequestBody UserPracticeDetail detail) {
        int result = detailService.addPracticeDetail(detail);
        return result > 0 ? "添加成功" : "添加失败";
    }
}